import {
  Inject,
  Controller,
  Post,
  Put,
  Del,
  Get,
  Param,
  Body,
  Queries
} from "@midwayjs/core";
import { Context } from "@midwayjs/koa";
import { Utils } from "../utils/index";
import { PartService } from "../service/part.service";
import { PartCreateDto, PartPageQueryDto } from "../dto/part.dto";

@Controller()
export class PartController {
  @Inject()
  ctx: Context;

  @Inject()
  partService: PartService;

  @Inject()
  utils: Utils;

  @Post("/auth-api/part", { summary: "添加配件" })
  async add_part(@Body() dto: PartCreateDto) {
    const result = await this.partService.add_part(dto);
    return this.utils.response.success({
      ...result
    });
  }
  @Put("/auth-api/part/:partId", { summary: "更新配件" })
  async update_part(
    @Param("partId") partId: string,
    @Body() dto: PartCreateDto
  ) {
    const result = await this.partService.update_part(partId, dto);
    return this.utils.response.success({
      ...result
    });
  }
  @Del("/auth-api/part/:partId", { summary: "删除配件" })
  async delete_part(@Param("partId") partId: string) {
    const result = await this.partService.delete_part(partId);
    return this.utils.response.success({
      ...result
    });
  }

  @Get("/common-api/part/list", { summary: "获取配件列表" })
  async get_part_list() {
    const result = await this.partService.get_part_list();
    return this.utils.response.success({
      ...result
    });
  }

  @Get("/common-api/part/page", { summary: "获取球杆分页列表" })
  async get_club_page_list(@Queries() dto: PartPageQueryDto) {
    const result = await this.partService.get_part_page_list(dto);
    return this.utils.response.success({
      ...result
    });
  }
}
